package com.ztgf.commodity.api.cms;

import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.commodity.models.bo.CommodityApplyAgentBO;
import com.ztgf.commodity.models.service.ICommodityApplyAgentService;
import com.ztgf.commodity.models.vo.CommodityApplyAgentLogVO;
import com.ztgf.commodity.models.vo.CommodityApplyAgentVO;
import com.ztgf.commodity.models.vo.CommoditySysUserVO;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 商品代理申请表控制器
 *
 * @author chenyu.wang
 * @Date 2020-06-23 17:07:09
 */

@RestController
@RequestMapping("/cms/commodityApplyAgent")
@Slf4j
@Api(value = "CommodityApplyAgentController", tags = "商品代理申请表接口")
public class CommodityApplyAgentController {

    @DubboReference
    private ICommodityApplyAgentService commodityApplyAgentService;

    @PostMapping(value = "/queryPageList")
    @ApiOperation(value = "后台管理系统代理申请列表", notes = "后台管理系统代理申请列表")
    public Result queryPageList(CommodityApplyAgentBO bo) {
        Page<CommodityApplyAgentVO> list = commodityApplyAgentService.queryPageList(bo);
        return new Result<>(list);
    }

    @PostMapping(value = "/updateManagerUser")
    @ApiOperation(value = "后台管理系统代理申请指定经办人", notes = "后台管理系统代理申请指定经办人")
    public Result updateManagerUser(Long id, Long managerUserId) {
        if (id == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        } else {
            boolean flag = commodityApplyAgentService.updateManagerUser(id, managerUserId);
            return new Result<>(flag);
        }
    }

    @PostMapping(value = "/updateState")
    @ApiOperation(value = "后台管理系统代理申请更新操作", notes = "后台管理系统代理申请更新操作")
    public Result updateState(Long id, Integer state, String content, Long managerUserId) {
        if (id == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        } else {
            boolean flag = commodityApplyAgentService.updateState(id, state, content, managerUserId);
            return new Result<>(flag);
        }
    }

    @PostMapping(value = "/queryLog")
    @ApiOperation(value = "后台管理系统代理申请日志", notes = "后台管理系统代理申请日志")
    public Result queryLog(Long id) {
        if (id == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        } else {
            List<CommodityApplyAgentLogVO> list = commodityApplyAgentService.queryLog(id);
            return new Result<>(list);
        }
    }

    @PostMapping(value = "/queryManagerUser")
    @ApiOperation(value = "后台管理系统代理申请查询经办人", notes = "后台管理系统代理申请查询经办人")
    public Result queryManagerUser() {
        List<CommoditySysUserVO> list = commodityApplyAgentService.queryManagerUser();
        return new Result<>(list);
    }

}
